import logging
import allure

def format_error(message, details=None):
    """格式化错误信息"""
    error_message = f"{message}: {details}" if details else message
    return error_message

def log_error(error_message):
    """记录错误信息到日志"""
    logging.error(error_message)
    allure.attach(
        body=error_message,
        name="错误信息",
        attachment_type=allure.attachment_type.TEXT
    )

def assert_and_log(condition, message, details=None):
    """统一断言并记录日志"""
    if not condition:
        error_message = format_error(message, details)
        log_error(error_message)
        assert False, error_message